package com.cs.manaer.controller;

import com.cs.manaer.controller.req.ListRoleReqMsg;
import com.cs.manaer.controller.req.MGLoginReqMsg;
import com.cs.manaer.controller.req.RoleReqMsg;
import com.cs.manaer.controller.res.ListCsmgRoleResMsg;
import com.cs.manaer.controller.res.MGLoginResMsg;
import com.cs.manaer.po.CsmgRole;
import com.cs.manaer.service.RoleService;
import com.lin.common.error.CustomRuntimeException;
import com.lin.common.rest.ResMsg;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

@RestController
@RequestMapping("/web")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @PostMapping("/listrole")
    public ResMsg<ListCsmgRoleResMsg> chatlist(@Valid @RequestBody ListRoleReqMsg reqMsg) {
        //BaseController.verify(bindingResult);
        ResMsg<ListCsmgRoleResMsg> urs = new ResMsg<>();
        return urs.withData(roleService.listrole(reqMsg.getPageSize(), reqMsg.getPageNo()));
    }

    @PostMapping("/addrole")
    public ResMsg<Integer> addrole(@Valid @RequestBody RoleReqMsg reqMsg) throws Exception {
        ResMsg<Integer> rm = new ResMsg<>();
        return rm.withData(roleService.addrole(reqMsg));
    }

    @PostMapping("/delrole/{id}")
    public ResMsg<Integer> delrole(@PathVariable Long id) throws Exception {
        ResMsg<Integer> rm = new ResMsg<>();
        return rm.withData(roleService.delrole(id));
    }
}
